let common = require('../../../utils/common.js')
Page({
  data: {
    detail: {}
  },
  id: 1,
  onLoad: function (options) {
    this.id = options.id;
    this.registerEvent();
  },
  registerEvent: function () {
    this.reqDetail();
  },
  reqDetail: function () {
    let that = this;
    common.asynPost(common.API.activity.detail, {
      id: that.id
    }, function (data) {
      if (data['detail']) {
        that.setData({
          detail: data['detail']
        });
      }
    })
  },
  activityBook: function () {
    let isApply = this.data.detail.isApply;
    if (typeof isApply == 'undefined' || isApply == 1) {
      wx.showToast({title:'活动报名未开始'});
    } else if (isApply == 2) {
      wx.showToast({title:'活动报名已结束'});
    } else{
      var json = {
        id: this.data.detail.id,
        title: this.data.detail.title,
        subhead: this.data.detail.subhead,
        startTime: this.data.detail.startTime,
        address: this.data.detail.address,
        price: this.data.detail.price,
        cover: this.data.detail.cover
      }
      wx.navigateTo({
        url: '../book/book?detail=' + JSON.stringify(json)
      });
    }
  },
  onShareAppMessage() {
    return {
      title: this.data.detail['title'],
      desc: this.data.detail['subhead'],
      path: 'pages/activity/detail/detail?id=' + this.data.detail.id
    }
  }
})